package GoCache

import (
	"sync"
)
import "./lru"

type cache struct {
	mu  sync.Mutex
	lru *lru.Cache
}

// MAX 默认 最大内存 200 MB
const MAX = 200

func (c *cache) add(key string, value string) {
	c.mu.Lock()
	defer c.mu.Unlock()
	if c.lru == nil {
		c.lru = lru.New(MAX)
	}
	c.lru.AddOrUpdate(key, []byte(value))
}
func (c *cache) get(key string) any {
	c.mu.Lock()
	defer c.mu.Unlock()
	if c.lru == nil {
		c.lru = lru.New(MAX)
		return nil
	}
	return c.lru.Select(key)
}
func (c *cache) delete(key string) {
	c.mu.Lock()
	defer c.mu.Unlock()
	if c.lru == nil {
		c.lru = lru.New(MAX)
	}
	c.lru.Remove(key)
}
func (c *cache) CurMemory() int64 {
	return c.lru.GetMemory() * 1024
}
